import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:localStorage.getItem('token')||'',
    userInfo:null
  },
  getters: {
    getName(state){
      if(state.userInfo){
        return state.userInfo.name
      }
      return ""
    }
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token;
      localStorage.setItem('token',token)
    },
    REMOVE_TOKEN(state) {
      state.token = '';
      localStorage.setItem('token','')
    },
    SET_USERINFO(state,value){
      state.userInfo=value
    }
  },
  actions: {
  },
  modules: {
  }
})
